const myObj={
    name:'window',
    age:19,
    scores:{
        Chinese:100,
        Math:100,
        englist:100
    }
}
Object.defineProperty(myObj,'gender',{
    value:'male',
    writable:true,
    configurable:true,
    enumerable:true,
})
Object.defineProperty(myObj,'hobbies',{
    value:{
        first:'swinmming',
        second:'books'
    },
    writable:true,
    configurable:true,
    enumerable:false,
})
console.log(Object.getOwnPropertyDescriptor(myObj,'name'));
console.log(Object.getOwnPropertyDescriptor(myObj,'gender'));
for(let key in myObj) {
    console.log(`${key}:${myObj[key]}`);
}
console.log('myObj===',myObj);


console.log('--------------------------------对象上的方法--------------------------------');
// Object.preventExtensions(originObj) 禁止扩展（禁止浅扩展）
const preventObj={
    name:'window',
    age:19,
    scores:{
        Chinese:100,
        Math:100,
        englist:100
    }
}
Object.preventExtensions(preventObj)
preventObj.name="global",
preventObj.scores.Chinese=99
preventObj.scores.physical=120
preventObj.gender="female"//在非严格模式下，创建属性gender会静默失败；严格模式下，会报错TypeError
delete preventObj.scores.Chinese
delete preventObj.age
console.log('preventObj====',preventObj);

// Object.seal(originObj) 密封（浅密封，除修改属性的值，不能添加新属性，不能重新配置，不能删除任何现有的属性）
// 实际上是调用Object.preventExtensions()并把所有的属性都标记为configurable:false
const sealObj={
    name:'window',
    age:19,
    scores:{
        Chinese:100,
        Math:100,
        englist:100
    }
}
Object.seal(sealObj)
sealObj.name="node"
sealObj.height=198
console.log(Object.getOwnPropertyDescriptor(sealObj,'name'));
// Object.defineProperty(sealObj,'name',{
//     configurable:true//不能重新配置，会报错TypeError
// })
delete sealObj.age//不能删除属性（直接属性）
sealObj.scores.Math=150
sealObj.scores.history=99
delete sealObj.scores.Chinese
console.log('sealObj====',sealObj);

// Object.assign(targetObj,originalObj,originalObj) 浅拷贝
//实际上会调用Object.seal()并把所有数据访问的属性标记为writable:false
const assignObj={
    name:'window',
    age:19,
    scores:{
        Chinese:100,
        Math:100,
        englist:100
    }
}
const shallowObj = Object.assign({},assignObj)
shallowObj.name='browser'
shallowObj.gender="female"
delete shallowObj.age
shallowObj.scores.Math=134
shallowObj.scores.physical=120
delete shallowObj.scores.Chinese
console.log('shallowObj=', shallowObj);
